<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>补充项目资料信息</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="//cdn.staticfile.org/webuploader/0.1.5/webuploader.min.js" charset="utf-8">
    </script>
    <script src="//cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
</head>

<body class="iframeBody">
<div class="Wrapper">
<div class="fieldset1 tabel_col clearFix">
		                     
		               		  <div class="fieldBox col_33">
				                    <div class="label">项目名称</div>
				                    <div class="field">
				                        ${prjFilesRecVO.prjNm}
				                    </div>
		               		 </div>
		               		  <div class="fieldBox col_33">
				                    <div class="label">客户名称</div>
				                    <div class="field">
				                        ${prjFilesRecVO.cstNm}
				                    </div>
		               		 </div>
		               		   <div class="fieldBox col_33">
				                    <div class="label">合同号</div>
				                    <div class="field">
				                        ${prjFilesRecVO.lsCntNo}
				                    </div>
		               		 </div>
		               		  <div class="fieldBox col_33">
				                    <div class="label">支付表号</div>
				                    <div class="field">
				                        ${prjFilesRecVO.paySchNo}
				                    </div>
		               		 </div>
</div>
    <div class="fieldset1 tabel_col tabel_col_s clearFix">
        <div class="sqPanel">
        	
            <div class="sqPanel_head inL" >
            	
                <span>租赁物资料</span>
            </div>
            <div class="sqPanel_body">
                <div id="mateGrid1" class="sq-grid"></div>
            </div>
        </div>

        <div class="sqPanel">
            <div class="sqPanel_head inL">
            	
                <span>项目资料</span>
            </div>
            <div class="sqPanel_body">
                <div id="prjFileInfoCfgGrid" class="sq-grid"></div>
            </div>
        </div>

    </div>
	<div class="btnsBox formBtns "  style="text-align:center">
						<c:if test="${ctrlKey==4}">
						<span id="addBtn" class="sq-button sq-button-round fileupload-button" onclick="saveFlow(${prjPrdDtlId});">发起流程</span>
						</c:if>
	</div>
    <input type="text" style="display: none;" id="prjPrdDtlId" name="prjPrdDtlId" value="${prjPrdDtlId}">
    <input type="text" style="display: none;" id="prjId" name="prjId" value="${prjId}">
</div>

<script type="text/javascript" src="<%=path%>/resource/lib/plugins/ajaxfileupload.js"></script>
<script type="text/javascript">
    //租赁物资料
    var mateGrid = null;
    //项目资料配置明细
    var prjFileInfoCfgGrid = null;
    //客户资料配置明细
    var cstFileInfoCfgGrid = null;
    //狮桥对客合同
    var sqLsCntGrid = null;
    //三方对客合同
    var thirdLsCntGrid = null;
    //三方对客视频
    var thirdVideoGrid = null;
    var thirdVideoUpload;
    $(function () {
        var ctrlKey='${ctrlKey}';

        mateGrid = $("#mateGrid1").ligerGrid({
            url: '<%=path%>/project/prjfile/prjFileRec/initMateList.do?prjId=${prjId}&prjPrdDtlId=${prjPrdDtlId}&tabNm=PRJ_PRD_DTL',
            method: 'get',
            columns: [
                /*{display: '资料类型', name: 'cfgNm', minWidth: 100, align: 'left', enabledSort: false},*/
                {display: '资料名称', name: 'datNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h = rowdata.datNm;
                        if(rowdata.isMust == 1){
                            h += '(<span style="color:red;">*</span>)';
                        }
                        return h;
                    }
                },
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '验证状态', name: 'audStsCdNm', width: 100, align: 'left', enabledSort: false},
                {display: '操作', name: 'upLoadNm', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(rowdata.fileId){
                            if(ctrlKey==1||ctrlKey==4){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1,'+rowdata.id+')"></span>';
                                if(rowdata.audStsCd!=1) {
                                    h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(' + rowdata.fileId + ',\''+rowdata.orgCd+'\',1);">删除</span>';
                                }
                            }else if(ctrlKey==2){                                
                                if(rowdata.filePath) {
                                    h += '<a class="sq-button-hasicon  button_tongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',1,1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                    h += '<a class="sq-button-hasicon  button_butongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',2,1);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                }                                
                        	}
                        }else{
                            if(ctrlKey==1||ctrlKey==4 ){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',1,'+rowdata.id+')"></span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,

            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: function (s) {
                $('#mateGrid1').rowspan('datNm');
            }
        });

        //项目资料Grid
        prjFileInfoCfgGrid = $("#prjFileInfoCfgGrid").ligerGrid({
        	url: '<%=path%>/project/prjfile/prjFileRec/initMateList.do?prjId=${prjId}&prjPrdDtlId=${prjPrdDtlId}&tabNm=PRJ_BSC_INFO',
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm',align: 'left', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h = rowdata.datNm;
                        if(rowdata.isMust == 1){
                            h += '(<span style="color:red;">*</span>)';
                        }
                        return h;
                    }
                },
                {display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        if(value){
                            //return '<a target="_blank" name="showimg" href="'+rowdata.filePath+'">'+rowdata.fileNm+'</a>';
                            var h;
                            h='<a href="javascript:uploadFileByUrl(';
                            h+="'"+rowdata.filePath+"'";
                            h+=",'"+rowdata.fileNm+"'";
                            h+=')">'+rowdata.fileNm+'</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm',align: 'left', minWidth: 100, enabledSort: false,render:renderDate},
                {display: '验证状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                {display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render:function(rowdata,rowindex,value){
                        var h='';
                        if(rowdata.fileId){
                            if(ctrlKey==1||ctrlKey==4 ){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',3,'+rowdata.id+')"></span>';
                                if(rowdata.audStsCd!=1) {
                                    h+='<span class="sq-button sq-button-round fileupload-button" onclick="delFile(' + rowdata.fileId + ',\''+rowdata.orgCd+'\',3);">删除</span>';
                                }
                            }else if(ctrlKey==2){                                
                                    if(rowdata.filePath) {
                                        h += '<a class="sq-button-hasicon  button_tongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',1,3);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                        h += '<a class="sq-button-hasicon  button_butongguo"  style="cursor:pointer;" onclick="modifyAudStsCd(' + rowdata.fileId + ',2,3);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                                    }                                
                            }
                        }else{
                            if(ctrlKey==1||ctrlKey==4  ){
                                h+='<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'" multiple name="fileup_'+rowdata.cfgCd+'_'+rowdata.cfgDtlCd+'"' +
                                    ' class="fileupload-input" onchange="onChangefile_multi(event,\''+rowdata.cfgCd+'\',\''+rowdata.cfgDtlCd+'\',\''+rowdata.orgCd+'\',3,'+rowdata.id+')"></span>';
                            }
                        }
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: true,
            allowUnSelectRow:true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function (){
                $('#prjFileInfoCfgGrid').rowspan('datNm');
            },
        });


    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //删除文件
    function delFile(_fileId,_orgCd,typ){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'id':${prjId},'fileId':_fileId,'orgCd':_orgCd},
            url: '<%=path%>/capital/capPayInfo/removeMate.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    if(typ==1){
                        parent.$('li[tabid="mateTab"] a').text('放款资料('+msg.data+')');
                        mateGrid.reload();
                    }else if(typ==2){
                        cstFileInfoCfgGrid.reload();
                    }else if(typ==3){
                        prjFileInfoCfgGrid.reload();
                    }else if(typ==4){
                        sqLsCntGrid.reload();
                    }else if(typ==5){
                        thirdLsCntGrid.reload();
                    }else if(typ==6){
                        thirdVideoGrid.reload();
                    }
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    //修改资料的验证状态
    function modifyAudStsCd(_fileId,_audStsCd,typ){
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId':_fileId,'audStsCd':_audStsCd},
            url: '<%=path%>/capital/capPayInfo/modifyAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    if(typ==1){
                        mateGrid.reload();
                    }else if(typ==2){
                        cstFileInfoCfgGrid.reload();
                    }else if(typ==3){
                        prjFileInfoCfgGrid.reload();
                    }else if(typ==4){
                        sqLsCntGrid.reload();
                    }else if(typ==5){
                        thirdLsCntGrid.reload();
                    }else if(typ==6){
                        thirdVideoGrid.reload();
                    }
                }else{
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function onChangefile_multi(e,cfgCd,cfgDtlCd,orgCd,typ,id) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath="";
        if(typ==1){
            filePath="capital/capPayInfo";
        }else if(typ==2){
            filePath="customer";
        }else if(typ==3 || typ==4 ||typ==5){
            filePath="prjFileInfo";
        }

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    if(typ==1 || typ==4 ||typ==5) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {
                                'fileParams': JSON.stringify(msg.data),
                                'prjPrdDtlId': id,
                                'prjId': id,
                                'cfgCd': cfgCd,
                                'cfgDtlCd': cfgDtlCd,                                
                                'orgCd': orgCd
                            },
                            url: '<%=path%>/capital/capPayInfo/uploadMate.do',
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {
                                    if(typ == 1){
                                        parent.$('li[tabid="mateTab"] a').text('放款资料(' + msg.data + ')');
                                        mateGrid.reload();
                                    }else if(typ == 4){
                                        sqLsCntGrid.reload();
                                    }else{
                                        thirdLsCntGrid.reload();
                                    }
                                } else {
                                    $.ligerDialog.SQalert({content: "资料上传失败", SQ_type: "error"});
                                }
                            }
                        });
                    }else if(typ==2){
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {'fileParams':JSON.stringify(msg.data),'cstId':id,'cfgCd':cfgCd,'cfgDtlCd':cfgDtlCd,'orgCd':orgCd},
                            url: '<%=path%>/project/prjFileInfo/uploadCstFile.do',
                            success: function (msg) {
                                if (msg.success == 1) {
                                    cstFileInfoCfgGrid.reload();
                                }else{
                                    $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                                }
                                $.ligerDialog.hide();
                            }
                        });
                    }else if(typ==3){
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {'fileParams':JSON.stringify(msg.data),'prjId':id,'cfgCd':cfgCd,'cfgDtlCd':cfgDtlCd,'orgCd':orgCd},
                            url: '<%=path%>/project/prjFileInfo/uploadPrjFile.do',
                            success: function (msg) {
                                if (msg.success == 1) {
                                    prjFileInfoCfgGrid.reload();
                                }else{
                                    $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                                }
                                $.ligerDialog.hide();
                            }
                        });
                    }
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    function uploadFileByUrl(_url,_name){
        if(SQ.regs.img.test(_name)){
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        }else{
            window.open(_url);
        }
    }
    function downloadFileByUrl(tabNm) {
        var data;
        if(tabNm == 'mateGrid'){
            data = mateGrid.getData();
        }else if(tabNm == 'prjFileInfoCfgGrid'){
            data = prjFileInfoCfgGrid.getData();
        }else if(tabNm == 'cstFileInfoCfgGrid'){
            data = cstFileInfoCfgGrid.getData();
        }else if(tabNm == 'sqLsCntGrid'){
            data = sqLsCntGrid.getData();
        }else if(tabNm == 'thirdLsCntGrid'){
            data = thirdLsCntGrid.getData();
        }else if(tabNm == 'thirdVideoGrid'){
            data = thirdVideoGrid.getData();
        }else{
            $.ligerDialog.SQalert({content:"数据错误，请刷新后重试！", SQ_type: "error"});
            return;
        }
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            if(data[i].fileId){
                ids.push(data[i].fileId);
            }
        }
        if(ids.length <= 0){
            $.ligerDialog.SQalert({content:"没有要下载的附件！", SQ_type: "error"});
            return;
        }
        var actoinURL = '<%=path%>/system/sysulfilesrec/zipDownloadById.do';
        var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);//下载文件的请求路径
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','ids');
        input.attr('value',JSON.stringify(ids));
        form.append(input);
        form.submit();
    }
function saveFlow(id){
	$("#addBtn").attr("style","display:none;");
	$.ajax({
        type: 'post',
        dataType: 'json',
        data: {'id':id,'paySchNo':'${prjFilesRecVO.paySchNo}'},
        url: '<%=path%>/project/prjfile/prjFileRec/saveFlow.do',
        beforeSend: function(){
			wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		},
        success: function (msg) {
            if (msg.success == 1) {
            	//alert(msg.info);
            	top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
				Remove_navTab();//新增，关闭当前页面
				
            }else{
            	//alert(msg.info); 
            	top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
                
            }
            $.ligerDialog.hide();
        }
    });
}
</script>

</body>
</html>
